package com.tiantian.quanminxiu.presenter;

import com.shenglian.utils.utils.CommonUtils;
import com.tiantian.quanminxiu.api.AnchorService;
import com.tiantian.quanminxiu.utils.ApplicationBase;
import com.tiantian.quanminxiu.utils.Constants;
import com.tiantian.quanminxiu.utils.UserData;
import com.tiantian.quanminxiu.view.MainMineView;

import rx.android.schedulers.AndroidSchedulers;

/**
 * Created by admin on 2016/8/11.
 */
public class MainMinePresent implements Presenter<MainMineView> {

    private MainMineView mainMineView;

    @Override
    public void attachView(MainMineView view) {
        this.mainMineView = view;
    }

    @Override
    public void detachView() {
        mainMineView = null;
    }


    public void logout(){
        mainMineView.Loading_Open();
        ApplicationBase app = ApplicationBase.get(mainMineView.getContext());
        AnchorService service = app.getAnchorService();
        service.logout(UserData.Current.mid, UserData.Current.sign, Constants.APP_TYPE)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(app.defaultSubscribeScheduler())
                .finallyDo(()->{
                    mainMineView.Loading_Close();
                })
                .subscribe(str -> {
                    //清除用户数据
                    UserData.Base.clear();
                    mainMineView.logout();
                }, throwable -> {
                    CommonUtils.showToask(mainMineView.getContext(), throwable.getMessage());
                });

    }

}
